package edu.gdkm.sql.dao;

import edu.gdkm.sql.pojo.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ProductMapper {
    @Select("SELECT * FROM product")
    List<Product> findAll();

    // 根据id查询类别
    @Select("SELECT * FROM product WHERE id = #{id}")
    Product findById(int id);

    // 添加类别
    @Insert("INSERT INTO product(goodsname,price,typeid) VALUES(#{goodsname},#{price},#{typeid})")
    int insertProduct(Product product);

    // 更新类别
    @Update("UPDATE product SET goodsname=#{goodsname},price=#{price},typeid=#{typeid} WHERE id=#{id}")
    int updateProductById(Product product);

    // 删除类别
    @Delete("DELETE FROM product WHERE id=#{id}")
    int deleteProductById(int id);

    @Select("SELECT * FROM product WHERE goodsname like concat('%',#{goodsname},'%') AND price < #{price}")
    List<Product> findByGoodsnameAndPrice(@Param("goodsname") String goodsname,@Param("price") double price);

}
